#pragma once

#include <compl.h>
#include <dbg/printf.h>
#include <dbg/cycles.h>

// /* 用来统计时间 */
// // DECL_MEFF(int, tmitv_print, (const char *fmt, ...))

// CEFF_FTYPE(int, tmitv_print, (const char *fmt, ...))
// CEFF_FTYPE(word_t, tmitv_intv_ns_bits , ())

// CEFF_FTYPE(word_t, tmitv_intv_num , ())
// CEFF_HANDLER(tmitv, tmitv_print, tmitv_intv_ns_bits, tmitv_intv_num)

// // #define TIME_INTV_NS 1024
// // #define TIME_INTV_NUM 1023
// // #define TIME_MAX_INTV  (TIME_INTV_NS * TIME_INTV_NUM)

// typedef struct{
//     word_t cnt;
//     word_t itv_arr[];
// }tmitv_t;

// static inline tmitv_t *__tmitv_create_arr(void *ptr, tmitv_chdl_t *hdl){
//     tmitv_t *p = (tmitv_t *)ptr;
//     __memset(p, 0, (hdl->tmitv_intv_num + 1) * sizeof(word_t));
//     p->cnt = 0;
//     return p;
// }

// static inline void __tmitv_record(tmitv_t *p, word_t timens, tmitv_chdl_t *hdl){
//     word_t idx = timens >> (hdl->tmitv_intv_ns_bits);
//     if (idx >= (hdl->tmitv_intv_num)) idx = (hdl->tmitv_intv_num) - 1;
//     p->cnt++;
//     p->itv_arr[idx]++;
// }

// static inline void __tmitv_sum(tmitv_t *sum, tmitv_t *p, tmitv_chdl_t *hdl){
//     sum->cnt += p->cnt;
//     for (word_t i = 0 ; i < (hdl->tmitv_intv_num); i++){
//         sum->itv_arr[i] += p->itv_arr[i];
//     }
// }

// static inline void __tmitv_info(tmitv_t *p, tmitv_chdl_t *hdl){
//     hdl->tmitv_print("tmitv print %p, total record cnt %llu\n", p, p->cnt);
//     for (word_t i = 0 ; i < hdl->tmitv_intv_num; i++){
//         if(p->itv_arr[i]>20)hdl->tmitv_print("[%llu]%llu\n", (i+1) << (hdl->tmitv_intv_ns_bits), p->itv_arr[i]);
//     }
// }

// #define DEF_TMITV(name, time_intv_num, time_intv_ns_bits, printfunc)\
// DEF_CEFF_HANDLER(name, printfunc, time_intv_ns_bits, time_intv_num)\
// /* 把这些接口都封装起来, 这样比较好管理 */\
// static inline tmitv_t * name##_create_arr(void *ptr){ return __tmitv_create_arr(ptr, hdl); }\
// static inline void name##_record(tmitv_t *p, word_t timens){ __tmitv_record(p, timens, hdl); }\
// static inline void name##_sum(tmitv_t *sum, tmitv_t *p){ __tmitv_sum(sum, p, hdl); }\
// static inline void name##_info(tmitv_t *p){ __tmitv_info(p, hdl);}


